package com.molichuxing.gateway.bff.car.convertor;


import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.molichuxing.gateway.bff.car.entity.request.create.AccidentCaseCreateVo;
import com.molichuxing.gateway.bff.car.entity.response.AccidentCaseVo;
import com.molichuxing.gateway.bff.car.entity.response.AccidentDriveVo;
import com.molichuxing.gateway.bff.car.entity.response.AccidentImageVo;
import com.molichuxing.gateway.bff.car.entity.response.AccidentVo;
import com.molichuxing.gateway.bff.car.entity.response.CarDeliveryVo;
import com.molichuxing.gateway.bff.car.entity.response.PdiCheckVo;
import com.molichuxing.services.business.dto.response.AccidentAppBizDto;
import com.molichuxing.services.business.dto.response.AccidentCaseAppDto;
import com.molichuxing.services.business.dto.response.AccidentDriveAppBizDto;
import com.molichuxing.services.business.dto.response.AccidentImageAppBizDto;
import com.molichuxing.services.business.dto.response.PdiCheckBizDto;
import com.molichuxing.services.infrastructure.dto.request.create.AccidentCaseCreateDto;
import com.molichuxing.services.infrastructure.dto.response.CarDto;
import com.molichuxing.services.property.CarAccidentCasualtyEnum;
import com.molichuxing.services.property.CarAccidentDamageEnum;
import com.molichuxing.services.property.CarAccidentDieEnum;
import com.molichuxing.services.property.CarAccidentDriveTypeEnum;
import com.molichuxing.services.property.CarAccidentDutyEnum;
import com.molichuxing.services.property.CarAccidentLiabilityTypeEnum;
import com.molichuxing.services.property.CarAccidentStatusEnum;
import com.molichuxing.services.property.CarAccidentTypeEnum;
import com.molichuxing.services.property.OrderTypeEnum;

public class Convert {


    public static AccidentVo toAccidentVo(AccidentAppBizDto accidentAppBizDto) {
        AccidentVo accidentVo = null;
        if (null == accidentAppBizDto) {
            return accidentVo;
        }
        accidentVo = new AccidentVo();
        BeanUtils.copyProperties(accidentAppBizDto, accidentVo);
        accidentVo.setIsCasualty(accidentAppBizDto.getIsCasualty() == true ? CarAccidentCasualtyEnum.YES.getValue() : CarAccidentCasualtyEnum.NO.getValue());
        accidentVo.setIsCasualtyStr(accidentAppBizDto.getIsCasualty() == true ? CarAccidentCasualtyEnum.YES.getName() : CarAccidentCasualtyEnum.NO.getName());
        accidentVo.setIsDamage(accidentAppBizDto.getIsDamage() == true ? CarAccidentDamageEnum.YES.getValue() : CarAccidentDamageEnum.NO.getValue());
        accidentVo.setIsDamageStr(accidentAppBizDto.getIsDamage() == true ? CarAccidentDamageEnum.YES.getName() : CarAccidentDamageEnum.NO.getName());
        accidentVo.setAccidentTypeStr(CarAccidentTypeEnum.getName(accidentAppBizDto.getAccidentType()));
        accidentVo.setLiabilityTypeStr(CarAccidentLiabilityTypeEnum.getName(accidentAppBizDto.getLiabilityType()));
        if(null != accidentAppBizDto.getType()){
            accidentVo.setTypeStr(CarAccidentDutyEnum.getName(accidentAppBizDto.getType()));
        }
        accidentVo.setStatusStr(CarAccidentStatusEnum.getName(accidentAppBizDto.getStatus()));
        return accidentVo;
    }

    public static PdiCheckVo toPdiCheckVo(PdiCheckBizDto pdiCheckBizDto) {
        PdiCheckVo accidentVo = null;
        if (null == pdiCheckBizDto) {
            return accidentVo;
        }
        accidentVo = new PdiCheckVo();
        return accidentVo;
    }


    public static AccidentDriveVo toAccidentDriveVo(AccidentDriveAppBizDto accidentDriveAppBizDto) {
        AccidentDriveVo accidentDriveVo = null;
        if (null == accidentDriveAppBizDto) {
            return accidentDriveVo;
        }
        accidentDriveVo = new AccidentDriveVo();
        BeanUtils.copyProperties(accidentDriveAppBizDto, accidentDriveVo);
        accidentDriveVo.setTypeStr(CarAccidentDriveTypeEnum.getName(accidentDriveAppBizDto.getType()));

        return accidentDriveVo;
    }

    public static List<AccidentImageVo> toAccidentImageVo(List<AccidentImageAppBizDto> beanDtoList) {
        List<AccidentImageVo> beanVoList = null;
        if (beanDtoList != null && !beanDtoList.isEmpty()) {
            beanVoList = new ArrayList<>();
            for (AccidentImageAppBizDto beanDto : beanDtoList) {
                beanVoList.add(toAccidentImageVo(beanDto));
            }
        }
        return beanVoList;
    }

    private static AccidentImageVo toAccidentImageVo(AccidentImageAppBizDto beanDto) {
        AccidentImageVo beanVo = null;
        if (beanDto != null) {
            beanVo = new AccidentImageVo();
            BeanUtils.copyProperties(beanDto, beanVo);
        }

        return beanVo;
    }

    public static AccidentCaseVo toaccidentCaseDetailVo(AccidentCaseAppDto accidentCaseAppDto) {
        AccidentCaseVo accidentCaseVo = null;
        if (null == accidentCaseAppDto) {
            return accidentCaseVo;
        }
        accidentCaseVo = new AccidentCaseVo();
        BeanUtils.copyProperties(accidentCaseAppDto, accidentCaseVo);
        accidentCaseVo.setIsDie(accidentCaseAppDto.getIsDie() == true ? CarAccidentDieEnum.YES.getValue() : CarAccidentDieEnum.NO.getValue());
        accidentCaseVo.setIsDieStr(accidentCaseAppDto.getIsDie() == true ? CarAccidentDieEnum.YES.getName() : CarAccidentDieEnum.NO.getName());
        accidentCaseVo.setStatusStr(CarAccidentStatusEnum.getName(accidentCaseAppDto.getStatus()));
        return accidentCaseVo;
    }

    public static AccidentCaseCreateDto toAccidentCaseCreateDto(AccidentCaseCreateVo accidentCaseCreateVo) {
        AccidentCaseCreateDto accidentCaseCreateDto = null;
        if (null == accidentCaseCreateVo) {
            return accidentCaseCreateDto;
        }
        accidentCaseCreateDto = new AccidentCaseCreateDto();
        BeanUtils.copyProperties(accidentCaseCreateVo, accidentCaseCreateDto);
        accidentCaseCreateDto.setIsDie(accidentCaseCreateVo.getIsDie() == 1 ? true : false);
        return accidentCaseCreateDto;
    }

    public static List<CarDeliveryVo> toCarDeliveryVo(List<CarDto> beanDtoList, String serverUrl,OrderTypeEnum orderType) {
        List<CarDeliveryVo> beanVoList = null;
        if (beanDtoList != null && !beanDtoList.isEmpty()) {
            beanVoList = new ArrayList<>();
            for (CarDto beanDto : beanDtoList) {
                beanVoList.add(toCarDeliveryVo(beanDto, serverUrl,orderType));
            }
        }
        return beanVoList;
    }

	public static CarDeliveryVo toCarDeliveryVo(CarDto beanDto, String serverUrl, OrderTypeEnum orderType) {
        CarDeliveryVo beanVo = null;
        if (beanDto != null) {
            beanVo = new CarDeliveryVo();
            BeanUtils.copyProperties(beanDto, beanVo);
            beanVo.setCarId(beanDto.getId());
            beanVo.setVehicleUrl(serverUrl);
            beanVo.setBusinessType(orderType.getValue());
        }

        return beanVo;
    }
}
